<template>
  <div class="contractOrder">
    <div class="order-content">
      <p class="title">充值记录</p>
      <div v-show="color==0?true:false" class="currentEntrust">
        <el-table :data="currentEntrust" style="width: 100%">
          <el-table-column prop="amount" label="金额" width="370">
            <template slot-scope="scope">
              <span>{{ scope.row.create_date | timing}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="amount" label="订单状态" width="370">
            <template slot-scope="scope">
              <span v-if="scope.row.state == 0">处理中</span>
              <span v-if="scope.row.state == 1">成功</span>
              <span v-if="scope.row.state == 2">失败</span>
            </template>
          </el-table-column>
          <el-table-column prop="amount" label="金额" width="170"></el-table-column>
        </el-table>
      </div>
      <!-- 详情弹框 -->
     

    </div>
  </div>
</template>
<script>
import moment from "moment";
import {
  getAllAgreement,
  positionGetlist,
  recordGetlist,
  modifyPosition,
  closePosition
} from "../api/api";
import qs from "qs";
import { mapState } from "Vuex";
export default {
  data() {
    return {
      orLogin: window.sessionStorage.getItem("user"),
      coinList: [],

      dialogVisible: false,
      DetailedData: {},
      // 1
      color: 0,
      // 2
      coinType: "",
      entrustType: "",
      dealType: "",
      startTime: "",
      endTime: "",
      closeOutType: "",
      // 3
      currentEntrust: [],
      historyEntrust: [],
      closeOut: [],
      // 4
      currentPage: 1,
      currentPageTwo: 1,
      totalOne: 0,
      totalTwo: 0,
      createDate: "",
      inputWin: "",
      inputLoss: "",
      value1: "0"
    };
  },

  computed: {
    ...mapState([
      "user",
      "tableList",
      "product",
      "BTCUSDT",
      "ETHUSDT",
      "LTCUSDT"
    ]),
    // 限价市价
    entrustList() {
      var entrustList = [
        {
          name: this.$t("message.price"),
          id: "1"
        },
        {
          name: this.$t("message.marketprice"),
          id: "2"
        }
      ];
      return entrustList;
    },
    // 买入开多
    dealList() {
      var dealList = [
        {
          name: this.$t("message.buymore"),
          id: "1"
        },
        {
          name: this.$t("message.sellmore"),
          id: "2"
        },
        {
          name: this.$t("message.moreflat"),
          id: "3"
        },
        {
          name: this.$t("message.jersey"),
          id: "4"
        }
      ];
      return dealList;
    },
    // 手动平仓
    closeOutList() {
      var closeOutList = [
        {
          name: this.$t("message.Manual"),
          id: "1"
        },
        {
          name: this.$t("message.Automatic"),
          id: "2"
        },
        {
          name: this.$t("message.Forced"),
          id: "3"
        }
      ];
      return closeOutList;
    }
  },
  created() {
    this.getEntrustList();
  },
  filters: {
    timing(val) {
      return moment(val).format("YYYY-MM-DD HH:mm:ss");
    }
  },
  methods: {
      subFun(arg1, arg2) {
            var r1, r2, m, n;
            try {
                r1 = arg1.toString().split(".")[1].length;
            } catch (e) {
                r1 = 0;
            }
            try {
                r2 = arg2.toString().split(".")[1].length;
            } catch (e) {
                r2 = 0;
            }
            m = Math.pow(10, Math.max(r1, r2));
            n = r1 >= r2 ? r1 : r2;
            return ((arg1 * m - arg2 * m) / m).toFixed(n);
        },
    close(row) {
      var params = {
        guid: "001",
        loginId: JSON.parse(this.orLogin).Customer.loginId,
        sessionId: JSON.parse(this.orLogin).SessionId,
        positionId: row.id
      };

      closePosition(params).then(res => {
        console.log(res);
        if (res.data.ResultCD == "I001") {
          this.$message({
            message: "平仓成功",
            type: "success"
          });
          this.dialogVisible = false;
          this.getEntrustList();
          this.getEntrustHistoryList();
        } else {
          this.$message.error(res.data.ErrorMsg);
        }
      });
    },
    
    dateFormat(row, column) {
      var moment = require("moment");
      var date = row[column.property];
      return moment(date).format("YYYY-MM-DD HH:MM:SS");
    },
    formatDate(now) {
      var year = now.getFullYear();
      var month = now.getMonth() + 1;
      var date = now.getDate();
      var hour = now.getHours();
      var minute = now.getMinutes();
      var second = now.getSeconds();
      return (
        year +
        "-" +
        month +
        "-" +
        date +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second
      );
    },
    details(row) {
      this.dialogVisible = true;

      this.DetailedData = row;
      this.createDate = moment(this.DetailedData.create_date).format(
        "YYYY-MM-DD HH:MM:SS"
      );
      this.inputWin = this.DetailedData.stop_win;
      this.inputLoss = this.DetailedData.stop_loss;
      this.value1 = this.DetailedData.cost_place;
      console.log(this.value1);
    },
    //当前持仓
    getEntrustList() {
      var params = {
        guid: "001",
        loginId: JSON.parse(this.orLogin).Customer.loginId,
        sessionId: JSON.parse(this.orLogin).SessionId,
        status: this.Status,
        skip:0,
        pagesize: 10,
      };
      recordGetlist(params).then(res => {
        this.currentEntrust = res.data.DepositList;
        console.log(this.currentEntrust, 654);
      });
    },
    //历史委托
    // getEntrustHistoryList() {
    //   var params = {
    //     guid: "001",
    //     loginId: JSON.parse(this.orLogin).Customer.loginId,
    //     sessionId: JSON.parse(this.orLogin).SessionId,
    //     skip: this.currentPageTwo,
    //     pagesize: 10
    //   };
    //   hisposition(params).then(res => {
    //     this.historyEntrust = res.data.PositionList;
    //   });
    // },
    //确定
    confrim() {
        this.getEntrustList()
    }
  }
};
</script>
<style lang="less" scoped>
.colorType {
  color: #6881ff;
  border-bottom: 2px solid #6881ff;
  padding-bottom: 5px;
}

.inputs {
  width: 120px;
  margin-right: 10px;
  .el-input__inner {
    background-color: #f7f7fb !important;
  }
}
.wt-btn {
  color: #6881ff;
}
.pc-btn {
  color: rgb(38, 102, 240);
}
.content {
  p {
    line-height: 40px;
    padding-left: 50px;
    span {
      padding: 0px 15px;
    }
  }
}
.contractOrder {
  min-height: 700px;
  padding: 120px 0;
  background-color: #fff;
  min-height: 700px;
  .order-content {
    max-width: 1200px;
    margin: 0 auto;
    color: #2d2f56;
    .title {
      font-size: 24px;
      font-weight: bold;
    }
    .order-type {
      margin: 20px 0 0;
      > span {
        font-size: 14px;
        margin-right: 30px;
        font-weight: bold;
        opacity: 0.8;
        cursor: pointer;
      }
    }
    .condition {
      margin: 30px 0 0;
      background-color: #f7f7fb;
      padding: 15px 10px;
      box-sizing: border-box;
    }
  }
}
</style>


